<?php
namespace Home\Model;
use Think\Model;
class ScategoryModel extends Model{
    
    
    function get_list($parent_id = -1)
    {
        
        if ($parent_id >= 0)
        {
            return $this->where('parent_id = '.$parent_id)->order('sort_order desc')->select();
        }
        else
        {
            return $this->order('sort_order desc')->select();
        }
    }
     /**
     * 取得某分类的所有子孙分类id
     */
    function get_descendant($id)
    {
        $ids = array($id);
        $this->_get_descendant($ids, $id);
        return $ids;
    }
    function _get_descendant(&$ids, $id)
    {
        $childs = $this->where("parent_id = ".$id)->select();
        foreach ($childs as $child)
        {
            $ids[] = $child['cate_id'];
            $this->_get_descendant($ids, $child['cate_id']);
        }
    }  
}
?>
